/*
 * @lc app=leetcode.cn id=3106 lang=golang
 *
 * [3106] 满足距离约束且字典序最小的字符串
 */
package Solutions

// @lc code=start
func getSmallestString_(s string, k int) string {
	t := []byte(s)
	var mid byte = 'a' + 13
	for i := 0; i < len(t); i++ {
		if t[i] >= mid {
			tt := 'z' - t[i] + 1
			if int(tt) < k {
				k -= int(tt)
				t[i] = 'a'
			} else {
				t[i] -= byte(k)
				k = 0
				break
			}
		} else {
			tt := t[i] - 'a'
			if int(tt) < k {
				k -= int(tt)
				t[i] = 'a'
			} else {
				t[i] -= byte(k)
				k = 0
				break
			}
		}
	}
	return string(t)
}

// @lc code=end
